package com.lzw.breezeNovel.WebAdmin.controller;


import com.lzw.breezeNovel.WebAdmin.service.AdvertisementService;
import com.lzw.breezeNovel.WebAdmin.vo.AdvertisementVo;
import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.novel.Advertisement;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 *  广告管理
 */
@RestController
@RequestMapping("/admin")
@SuppressWarnings("all")
public class AdvertisementController {

    /**
     * 注入广告管理service
     */
    @Resource
    private AdvertisementService advertisementService;

    /**
     * 新增广告
     */
    @RequestMapping("/addAdvertisement")
    public Result add(@RequestBody Advertisement advertisement) {
        advertisementService.addAdvertisement(advertisement);
        return Result.ok();
    }

    /**
     * 获取所有的广告
     */
    @RequestMapping("/getAllAdvertisement")
    public Result<PaginationResultQuery<AdvertisementVo>> getAllAdvertisement(@RequestBody Advertisement advertisement) {
        PaginationResultQuery<AdvertisementVo> advertisementVoPaginationResultVo = advertisementService.getAllAdvertisement(advertisement);
        return Result.ok(advertisementVoPaginationResultVo);
    }

    /**
     * 编辑广告
     */
    @RequestMapping("/updateAdvertisement")
    public Result edit(@RequestBody Advertisement advertisement) {
        advertisementService.updateAdvertisement(advertisement);
        return Result.ok();
    }

    /**
     * 删除广告
     */
    @DeleteMapping("/deleteAdvertisement/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        advertisementService.deleteAdvertisement(id);
        return Result.ok();
    }

    /**
     * 暂停广告
     */
    @PutMapping("/pauseAdvertisement/{id}")
    public Result pause(@PathVariable("id") Integer id) {
        advertisementService.pauseAdvertisement(id);
        return Result.ok();
    }

    /**
     * 恢复广告
     */
    @PutMapping("/resumeAdvertisement/{id}")
    public Result resume(@PathVariable("id") Integer id) {
        advertisementService.resumeAdvertisement(id);
        return Result.ok();
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatchAdvertisement")
    public Result deleteBatch( @RequestBody Integer[] ids) {
        advertisementService.deleteAdvertisementBatch(ids);
        return Result.ok();
    }

}
